#ifndef DOUBLESPINBOX_H
#define DOUBLESPINBOX_H

#include <QtUiPlugin/QDesignerExportWidget>
#include <QAbstractSpinBox>
#include <QWidget>
#include <QFrame>

namespace Ui {
    class DoubleSpinBox;
}


class QDESIGNER_WIDGET_EXPORT DoubleSpinBox : public QWidget
{
    Q_OBJECT

    ///////// 定义可在QDesigner中设置的属性 //////////////
    //前缀
    Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
    //后缀
    Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
    //可清理的
    Q_PROPERTY(QString cleanText READ cleanText)
    //数据精度
    Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
    //最小值
    Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
    //最大值
    Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
    //增加和减少的步长
    Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
    //设置value
    Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)

public:

   explicit DoubleSpinBox(QWidget *parent = 0);

   ~DoubleSpinBox();


    //读取和设置前缀
    QString prefix() const;
    void setPrefix(const QString &prefix);

    //读取和设置后缀
    QString suffix() const;
    void setSuffix(const QString &suffix);

    //清空数据
    QString cleanText() const;

    //设置增加/减少的步长
    double singleStep() const;
    void setSingleStep(double val);

    //读取和设置最小值
    double minimum() const;
    void setMinimum(double min);

    //读取和设置最大值
    double maximum() const;
    void setMaximum(double max);

    //设置取值范围
    void setRange(double min, double max);

    //读取和设置数据精度
    int decimals() const;
    void setDecimals(int prec);

    //设置校验
    QValidator::State validate(QString &input, int &pos) const;

    //将字符串格式化成数字
    double valueFromText(const QString &text) const;

    //将数据格式化成字符串
    QString textFromValue(double val) const;

    //读取值
    double value() const;

public Q_SLOTS:
    //设置值
    void setValue(double val);

Q_SIGNALS:
    //值（double）发生变化时触发的信号
    void valueChanged(double);
    //值（QString）发生变化时触发的信号
    void textChanged(const QString &);

private slots:
    //增加按钮被点击的事件，按照设定的步长来增加值
    void on_addButton_clicked();
    //增加按钮被点击的事件，按照设定的步长来增加值
    void on_subButton_clicked();
    //输入框的数据变化时触发当前对象的textChanged信号
    void on_doubleSpinBox_textChanged(const QString &arg1);
    //输入框的数据变化时触发当前对象的valueChanged信号
    void on_doubleSpinBox_valueChanged(double arg1);

private:
    Ui::DoubleSpinBox *ui;

//private:
//    Q_DISABLE_COPY(DoubleSpinBox)
//    Q_DECLARE_PRIVATE(DoubleSpinBox)

};

#endif // DOUBLESPINBOX_H
